import React from 'react';
import { AppRegistry, Dimensions, DeviceEventEmitter} from 'react-native'; // 各种包一定要注意导入

// 跳转动画
import StackViewStyleInterpolator from 'react-navigation/src/views/StackView/StackViewStyleInterpolator';

console.disableYellowBox = true;
console.warn("YellowBox is disabled.");

import { NativeModules } from 'react-native';
import { StackNavigator } from 'react-navigation';

NativeModules.Wxpay.registerApp("wxed051da706bfc9c6"); //向微信注册

global.ECourseConstant = {};
global.gScreen = {
  width: Dimensions.get('window').width,
  height: Dimensions.get('window').height
};

NativeModules.BaseBridge.refreshToken();

import RouterConfig from './src/RouterConfig';
import CommonStyle from './src/common/CommonStyle';
import CommonStyleSheet from './src/common/CommonStyleSheet';

global.CommonStyle = CommonStyle;
global.CommonStyleSheet = CommonStyleSheet;

/* 为了注释烦人的调试提醒 */
console.ignoredYellowBox = true;//['Remote debugger'];

global.log = function (message,info) {
  // console.log(message,info);
}

export default class Main extends React.Component {
  constructor(props) {
    super(props);
    global.ECourseConstant = props.ECourseConstant;
    global.log(global, "====global======");
    // 测试版本添加这段注释
    // global.ECourseConstant.userInfo.studentId = '468774537639505920'; 
    // global.ECourseConstant.map["entryCourseId"]="484651832480759808"; 
    // global.ECourseConstant.map["entryLessonIds"]="484651907378446336,484651990777987072";
    // global.ECourseConstant.userInfo.userName='王梦贵';
    // 测试版本添加这段注释 end


    DeviceEventEmitter.addListener('TokenFreshed_NativeEmitter', function (token) {
      // alert("send success" + token);

      global.ECourseConstant.userInfo.token = token;
    });

  }
  render() {

    // global.ECourseConstant.eCourseFirstRouter = "A";
    var FirstRouter = global.ECourseConstant.eCourseFirstRouter || "HomePage";
    global.log(FirstRouter,"=======FirstRouter=====")
    if (RouterConfig.hasOwnProperty(FirstRouter)) {
      RouterConfig.FirstRouter = RouterConfig[FirstRouter];
    }


    const App = StackNavigator(RouterConfig, {
      navigationOptions: {
        header: null
      },
      // 跳转动画
      transitionConfig: () => ({
        screenInterpolator: StackViewStyleInterpolator.forHorizontal,
      }),
    });

    return (
      <App />
    )
  }
  
}
AppRegistry.registerComponent('eCourseApp', () => Main);